home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / nwtp06 / tstdh.pas < prev    next >
Pascal/Delphi Source File  |  1996-07-10  |  6KB  |  211 lines

  1. program tstdh;
  2.  
  3. { Testprogram for the nwFile unit / NwTP 0.6 API. (c) 1993,1995, R.Spronk }
  4.  
  5. uses nwMisc,nwConn,nwFile;
  6.  
  7. { Test the following drive(handle) related calls:
  8.  
  9.   GetDirectoryHandle
  10.   GetDirectoryPath
  11.   GetDriveConnectionId
  12.   GetDriveHandle
  13.   GetDriveFlag
  14.   GetNumberOfLocalDrives (nwConn)
  15.   GetVolumeNameWithHandle
  16.   IsNetworkDrive
  17.  
  18.   GetEnvPath
  19.   GetSearchDriveVector
  20.   IsSearchDrive
  21.   SetEnvPath
  22.   SetSearchDriveVector
  23.  
  24. }
  25.  
  26. Var t,dirhandle,status:byte;
  27.     status2,dirHandle2:byte;
  28.     volname:string;
  29.     connId:byte;
  30.     locDrives:byte;
  31.     dirPath:string;
  32.     serverName:string;
  33.  
  34.     NewDirHandle, EffectiveRights:byte;
  35.     connId2,Dflag:byte;
  36.  
  37.     vector,vector2:TsearchDriveVector;
  38.     pth,pth2:string;
  39.  
  40. begin
  41. {-- drivenumbers, dirhandles --}
  42.  
  43. nwconn.GetNumberofLocalDrives(locDrives);
  44. writeln('Local Drives:',locDrives); { Drivenumbers 0..locDrives-1 taken by local drives }
  45. writeln;
  46.  
  47. for t:=0 to locDrives-1
  48.  do If IsNetworkDrive(t)
  49.      then writeln('Error?: IsNetworkDrive failed for drive ',chr(ord('A')+t));
  50.  
  51. for t:=locDrives to 31
  52.  do begin
  53.     IF GetDirectoryHandle(t,dirHandle,status)
  54.      then begin
  55.           writeln(chr(t+ord('A')),' handle=',dirHandle,' status=',status);
  56.           GetDriveHandle(t,dirHandle2);
  57.           GetDriveFlag(t,status2);
  58.           if (status<>status2) or (dirHandle<>dirHandle2)
  59.            then writeln('Error: GetDirectoryHandle data differs from GetDriveHandle/Flag data.');
  60.  
  61.           if IsNetworkDrive(t) XOR ((status AND $80)=0)
  62.            then writeln('Error: IsNetworkDrive failed.');
  63.  
  64.           GetDirectoryPath(dirHandle,dirpath);
  65.           write('=> ',dirpath);
  66.  
  67.           if GetDriveConnectionId(t,connId)
  68.            then begin
  69.                 write(' connId=',connId);
  70.                 nwConn.GetFileServerName(connId,serverName);
  71.                 write(' volume=\\',servername,'\');
  72.                 end;
  73.  
  74.           IF (status<3) {temporary or permanent mapping}
  75.              and GetVolumeNameWithHandle(dirHandle,volName)
  76.            then write(volName);
  77.  
  78.           writeln;
  79.           end
  80.     end;
  81.  
  82.  
  83. {-- seachdrives, searchdrive vector-- }
  84. writeln;
  85. writeln('<RETURN> to continue..');
  86. writeln;
  87. readln;
  88.  
  89. GetSearchDriveVector(vector);
  90. write('Searchdrivevector: ');
  91. for t:=1 to 17
  92.  do if vector[t]<255
  93.      then write(chr(byte(vector[t]+ord('A'))),' ')
  94.      else write('$FF ');
  95. writeln;
  96.  
  97. FillChar(vector2,Sizeof(TsearchDriveVector),#$FF);
  98. SetSearchDriveVector(vector2);
  99. FillChar(vector2,Sizeof(TsearchDriveVector),#$00);
  100. GetSearchDriveVector(vector2);
  101. if (vector2[1]<>$FF)
  102.  then writeln('Error: SetSearchdriveVector Failed.');
  103. SetSearchDriveVector(vector); { restore old vector }
  104.  
  105. GetEnvPath(pth);
  106. writeln('PATH setting in the master environment=',pth);
  107. SetEnvPath('this_is_a_bogus_path;');
  108. GetEnvPath(pth2);
  109. writeln('Path is temporarily set to: ',pth2);
  110. SetEnvPath(pth);
  111. writeln('Path reset to original value.');
  112.  
  113. Write('Searchdrives (using IsSearchDrive):');
  114. for t:=locDrives to 31
  115.  do If IsSearchDrive(t)
  116.      then write(chr(t+ord('A')),' ');
  117. writeln;
  118.  
  119. {----------------- directory handles ---------------------}
  120. writeln('<RETURN> to continue..');
  121. writeln;
  122.  
  123. t:=locDrives;
  124. While (t<26) and GetDirectoryHandle(t,dirHandle,status)
  125.  do inc(t);
  126. Writeln('First free drive: ',chr(t+ord('A')));
  127.  
  128. IF NOT AllocPermanentDirHandle(t,0,'SYS:LOGIN',NewDirHandle, EffectiveRights)
  129.  then writeln('Error calling AllocPermanentDirHandle: ',nwFile.result);
  130.  
  131. GetDirectoryPath(NewDirHandle,pth);
  132. IF SetDriveHandle(t,NewDirHandle)
  133.  then writeln('SetDriveHandle: drive ',chr(t+ord('A')),' asociated with dirHandle to path ',pth)
  134.  else writeln('Error using SetDriveHandle: ',nwFile.result);
  135.  
  136. GetDriveHandle(t,dirHandle);
  137. if dirHandle<>NewDirHandle
  138.  then writeln('Error in SetDriveHandle.');
  139.  
  140. GetEffectiveConnectionId(connId);
  141. { all requests have been sent to the effective  server up to now, so
  142.   that's the server the drive is connected to }
  143. SetDriveConnectionId(t,connId);
  144. GetDriveConnectionId(t,connId2);
  145. If ConnId2<>ConnId
  146.  then writeln('Error in Set/GetDriveConnectionId');
  147. GetDriveFlag(t,Dflag);
  148. SetDriveFlag(t,(Dflag and $80) or 1);
  149.  
  150. writeln('(non-root) Mapping completed.');
  151. { see the MAPDRIVE function in nwFile;
  152.   it creates (temporary) mappings in much the same way as above }
  153.  
  154.  
  155. {map a temporary drive}
  156. IF MapDrive(31,'SYS:MAIL',{root drive:} false, {permanent mapping:} false {true})
  157.  then begin
  158.       GetDriveHandle(31,dirHandle);
  159.       GetDirectoryPath(dirHAndle,pth);
  160.       Writeln('Temporary! drive ',chr(31+ord('A')),' mapped to ',pth);
  161.       { If mapdrive works, so must
  162.  
  163.         DeleteFakeRootDirectory
  164.         GetTrueEntryName
  165.         MapFakeRootDirectory
  166.  
  167.       }
  168.       end
  169.  else writeln('Error using MapDrive: ',nwFile.result);
  170.  
  171.  
  172. writeln;
  173. t:=locDrives;
  174. While (t<26) and GetDirectoryHandle(t,dirHandle,status)
  175.  do inc(t);
  176. Writeln('Another free drive: ',chr(t+ord('A')));
  177.  
  178. IF MapSearchDrive(t,'SYS:PUBLIC',16,{insert:}false,
  179.                   {root:}false,{permanent:}true)
  180.  then begin
  181.       GetDriveHandle(t,dirHandle);
  182.       GetDirectoryPATh(dirHAndle,pth);
  183.       Writeln('drive ',chr(t+ord('A')),' mapped (as a searchdrive) to ',pth);
  184.       end
  185.  else writeln('Error using MapSearchDrive: ',nwFile.result);
  186.  
  187.  
  188. writeln;
  189. t:=locDrives;
  190. While (t<26) and GetDirectoryHandle(t,dirHandle,status)
  191.  do inc(t);
  192. Writeln('Another free drive: ',chr(t+ord('A')));
  193.  
  194. IF MapPermanentDrive(t,'SYS:PUBLIC',{root:}true)
  195.  then begin
  196.       GetDriveHandle(t,dirHandle);
  197.       GetDirectoryPATh(dirHAndle,pth);
  198.       Writeln('drive ',chr(t+ord('A')),' mapped (permanently) to ',pth);
  199.  
  200.       IF NOT SetDirectoryHandle(0,'SYS:MAIL',dirHandle)
  201.        then writeln('Error using SetDirectoryHandle: ',nwFile.result)
  202.        else begin
  203.             GetDirectoryPATh(dirHAndle,pth);
  204.             Writeln('drive ',chr(t+ord('A')),' => handle changed to ',pth);
  205.             end;
  206.  
  207.       end
  208.  else writeln('Error using MapPermanentDrive: ',nwFile.result);
  209.  
  210.  
  211. end.